<?php
/**
 * Created by PhpStorm.
 * User: 李一瑶
 * Date: 2019/3/6
 * Time: 14:52
 */

namespace App\Http\Repository;

use App\Http\Model\Users;
use App\Http\Service\UsersInterface;
use Mews\Captcha\Facades\Captcha;

class UsersRepository implements UsersInterface
{
    private $user;

    public function __construct(Users $user)
    {
        $this->user = $user;
    }

    public function login(array $data)
    {
        if(Captcha::check($data['captcha']))
        {
            unset($data['captcha']);
            if($token = auth()->guard('api')->attempt($data))
            {
                $id = auth()->id();
                return renderJson('登陆成功','Bearer '.$token,'200');
            }else{
                return renderJson('用户名或密码错误',null,500);
            }
        }else{
            return renderJson('验证码错误',null,500);
        }
    }
}